<?php
class ques_list {
	var $title='';
	var $flag=false;
	var $flag_title=false;
	var $page=false;
	var $evey_page_num=50;
	var $sql_where=false;
	var $ques_list=false;
	function __construct() {
		global $user;
		switch ($user->gm_level) {
			case '普通GM':
				$arrTitle=array('受理中','未受理','已受理','高级gm未受理','高级gm已受理','所有已质检');
				break;
			case '高级GM':
				$arrTitle=array('所有受理中','所有未受理','所有已受理','高级gm受理');
				break;
			case '质检GM':
				$arrTitle=array('等待质检','所有已质检','质检结果对','质检结果错');
				break;
		}
		if(isset($_GET['flag'])) $this->flag=urldecode($_GET['flag']);
		else $this->flag=$arrTitle[0];
		$flag=false;
		foreach ($arrTitle as $value) {
			if($value==$this->flag) {$flag=true;break;}
		}
		if(!$flag) $this->flag=$arrTitle[0];
		$this->flag_title=$this->flag;
		foreach ($arrTitle as $value) {
			if($this->title!='') $this->title.='|';
			if($this->flag!=$value)
			$this->title.=' <a href="index.php?flag='.urlencode($value).'"  style="text-decoration:underline; font-size:14px;">'.$value.'</a> ';
			else $this->title.=' <a href="index.php?flag='.urlencode($value).'"  style="font-weight:bold;color:red;font-size:14px;">'.$value.'</a> ';
		}
	}
	function get_list() {
		global $user;
		if(!isset($_GET['page'])) $this->page=1;
		else $this->page=$_GET['page'];
		$user_id=$user->id;
		$start=$this->evey_page_num*($this->page-1);
		$evey_page_num=$this->evey_page_num;
		//受理中
		if($this->flag=='受理中') $sql_where="gm_id=$user_id and solution_flag!=1";
		//所有受理中
		if($this->flag=='所有受理中') $sql_where="solution_flag!=1 and solution_flag!=0";
		//未受理
		if($this->flag=='未受理') $sql_where="solution_flag=0";
		//所有未受理
		if($this->flag=='所有未受理') $sql_where="solution_flag=0";
		//已受理
		if($this->flag=='已受理') $sql_where="(gm_id=$user_id or high_gm_id=$user_id) and solution_flag=1";
		//所有已受理
		if($this->flag=='所有已受理') $sql_where="solution_flag=1";
		//高级gm受理
		if($this->flag=='高级gm受理') $sql_where="solution_flag=3";
		
		//高级gm已受理
		if($this->flag=='高级gm已受理') $sql_where="solution_flag=2 and high_gm_back!=''";
		//高级gm未受理
		if($this->flag=='高级gm未受理') $sql_where="solution_flag=3";
		
		//质检
		if($this->flag=='等待质检') $sql_where="back_check=0";
		//已质检
		if($this->flag=='所有已质检') $sql_where="back_check=1";
		//质检对
		if($this->flag=='质检结果对') $sql_where="back_check=1 and check_yes_or_no=1";
		//质检错
		if($this->flag=='质检结果错') $sql_where="back_check=1 and check_yes_or_no=0";
				
		if(isset($_GET['set_game_id'])) {
			if($_GET['set_game_id']!='-1') {
				$sql_where.=' and question_info.game_id='.$_GET['set_game_id'];
			}
		}else {
			if(isset($_COOKIE['set_game_id'])) {
				if($_COOKIE['set_game_id']!=-1) {
					$sql_where.=' and question_info.game_id='.$_COOKIE['set_game_id'];
				}
			}
		}
		$this->sql_where=$sql_where;
		$sql="select solution_flag,question_info.id,question_info.title,question_info.ask_time,question_class.title from question_info,question_class where ".$sql_where." and question_info.class_id=question_class.class_id order by ask_time desc,question_info.class_id  limit $start,$evey_page_num";
		$this->ques_list=sql_get_arr($sql,__LINE__);
		for ($i=0;$i<$this->ques_list['sql']['count'];$i++){
			switch ($this->ques_list[$i]['solution_flag']) {
				case 0:
					$this->ques_list[$i]['state']='未解决';
					break;
				case 1:
					$this->ques_list[$i]['state']='已解决';
					break;
				case 2:
					$this->ques_list[$i]['state']='处理中';
					break;
				case 3:
					$this->ques_list[$i]['state']='高级gm处理中';
					break;
				case 4:
					$this->ques_list[$i]['state']='等待质检';
					break;				
			
				default:
					$this->ques_list[$i]['state']='未知';
					break;
			}
		}
		
		$this->get_page();
	}
	function get_page() {
		global $user;
		//获取总页数:
		$user_id=$user->id;
		$flag=urlencode($this->flag);
		$sql="select count(*) from question_info where ".$this->sql_where;
		$row=sql_get_one($sql,__LINE__);
		$total=$row['count(*)'];
		if($total==0) return;
		$total_page=ceil($total/$this->evey_page_num);

		$this->page_tpl='
		<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0"  style=" padding:0px; font-weight:bold;">
				<tr>';
		//首页
		$this->page_tpl.='
		<td width="60" align="center"  style=" padding:0px;"><a href="index.php?flag='.$flag.'">[首页]</a></td>
		';

		//上一页
		if($this->page>1) $last_page_no=$this->page-1;
		else $last_page_no=$this->page;
		$this->page_tpl.='
		<td width="60" align="center"  style=" padding:0px;"><a href="index.php?flag='.$flag.'&page='.$last_page_no.'">[上页]</a></td>
		';

		//中间
		$this->page_tpl.='<td align="center" style=" font-size:14px; padding:0px;">';

		for($i=$this->page-2;$i<$this->page+6 && $i<=$total_page;$i++)
		{
			if($i>0)
			{
				if($i==$this->page) $this->page_tpl.="<font color=red><b>[$i]</b></font> ";
				else $this->page_tpl.='<A href="index.php?flag='.$flag.'&page='.$i.'">['.$i.']</a> ';
			}
		}
		$this->page_tpl.='</td>';

		//下一页
		if($this->page<$total_page) $next_page_no=$this->page+1;
		else $next_page_no=$this->page;
		$this->page_tpl.='
		<td width="60" align="center"  style=" padding:0px;"><a href="index.php?flag='.$flag.'&page='.$next_page_no.'">[下页]</a></td>
		';

		//尾页
		$this->page_tpl.='
		<td width="60" align="center"  style=" padding:0px;"><a href="index.php?flag='.$flag.'&page='.$total_page.'">[尾页]</a></td>
		';

		$this->page_tpl.='
				</tr>
		</table>
		';
	}
}